home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
BARNET
/
FREENET
/
BRODIE
/
INTERNET
/
!InternetD
/
c
/
syslog
< prev
next >
Wrap
Text File
|
1995-06-08
|
2KB
|
66 lines
#include "inetd.h"
#include "syslog.h"
#include "oslib:osmodule.h"
static void syslog_exit(void)
{
xosmodule_free(sys()->data.syslog);
}
int syslog_init(void)
{
sys()->data.syslog = osmodule_alloc(sizeof(struct syslog));
if (!sys()->data.syslog) return 0;
atexit(syslog_exit);
sys()->data.syslog->want_foreground = 0;
return 1;
}
void syslog_udp(int s)
{
struct sockaddr_in sin;
int size = 16;
int result;
if (sys()->data.syslog->want_foreground) return; /* defer */
result = recvfrom(s, sys()->data.syslog->buffer, SYSLOGSIZE, 0,
(struct sockaddr *)&sin, &size);
if (sin.sin_addr.s_addr != 0x0100007f) {
/* drop it on the floor */
result = 0;
}
if (result > 0) {
if (result >= SYSLOGSIZE) result = SYSLOGSIZE - 1;
sys()->data.syslog->buffer[result] = '\0';
sys()->data.syslog->want_foreground = 1;
++(sys()->wimp_poll_word);
}
}
#define SYSLOG_INTBUF (SYSLOGSIZE + 64)
void syslog(int lev, char *message, ...)
{
static char intbuf[SYSLOG_INTBUF+4];
FILE *f;
va_list ap;
f = fopen("<InternetD$Dir>.debugger", "a");
if (!f) return;
fprintf(f, "\n%4d ", lev);
va_start(ap, message);
vfprintf(f, message, ap);
va_end(ap);
fclose(f);
}
void syslog_fg_data(inet_handler *ih)
{
UNUSED(ih);
if (sys()->data.syslog->want_foreground) {
syslog(0, "%s", sys()->data.syslog->buffer);
sys()->data.syslog->want_foreground = 0;
}
}